﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyMathLib
{
    public class DataFetch
    {
        /// <summary>
        /// 从指定路径的文件中读取数据并存储到List<double>中
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public static List<double> ListReadTxt(string path)
        {
            if (File.Exists(path))
            {
                List<double> list = new List<double>();
                //打开文件
                using (TextReader tr = File.OpenText(path))
                {
                    string str = tr.ReadToEnd();
                    var ss = str.Split(' ');
                    list = ss.Select(m => double.Parse(m)).ToList();
                    return list;
                }
            }
            else
                throw new Exception($"数据文件{path}不存在");
        }
    }
}
